<template>
  <div>
    <div id="main" style="width: 300px; height: 200px"></div>
  </div>
</template>

<script>
import axios from "../../http/axios";
import * as echarts from "echarts";

export default {
  data() {
    return {
      date: [],
      values: [],
      userid: localStorage.getItem("userid"),
    };
  },
  methods: {
    add() {
      var chartDom = document.getElementById("main");
      var myChart = echarts.init(chartDom);
      var option;
      option = {
        xAxis: {
          type: "category",
          data: this.date,
        },
        yAxis: {
          type: "value",
        },
        series: [
          {
            data: this.values,
            type: "line",
          },
        ],
      };

      option && myChart.setOption(option);
    },
    get_data() {
      axios("/echarts?userid=" + this.userid, "get").then((res) => {
        console.log(res);
        this.date = res.date;
        this.values = res.values;
        this.add();
      });
    },
  },
  mounted() {
    this.get_data();
  },
};
</script>

<style>
</style>